﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RegisterationCommon.Common;
using System.Data;

namespace RegisterationCommon.Help
{
    /// <summary>
    /// 帮助内容信息实体类
    /// </summary>
    public class HelpContent
    {
        #region 局部变量
        //主键，自动编号
        private int _ID = 0;
        //帮助标题
        private string _Tile = "";
        //帮助内容
        private string _Content = "";
        //分类ID
        private int _SubjectID = 0;
        #endregion

        #region 属性列表
        /// <summary>
        /// 分类ID
        /// </summary>
        public int SubjectID
        {
            get { return _SubjectID; }
            set { _SubjectID = value; }
        }
        /// <summary>
        /// 帮助内容
        /// </summary>
        public string Content
        {
            get { return _Content; }
            set { _Content = value; }
        }
        /// <summary>
        /// 帮助标题
        /// </summary>
        public string Tile
        {
            get { return _Tile; }
            set { _Tile = value; }
        }
        /// <summary>
        /// 主键，自动编号
        /// </summary>
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        #endregion

        #region 方法列表
        #region 查询帮助信息列表
        /// <summary>
        /// 分页获取查询帮助信息列表
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>返回JSON格式的字符串</returns>
        public string GetHelpContentList(RParams RP)
        {
            //查询当前页
            DataTable dt = DBAction.ExecSP("sp_select_page", RP).Tables[0];
            //查询条件的总条数
            int totalCount = DBAction.GetDTFromSQL("select * from " + ETableName.HelpContent + " where " + RP.GetSqlParameter("Where").Value).Rows.Count;
            //返回Json
            return DBAction.DataTableToJson(dt, true, totalCount);
        }
        #endregion

        #region 查询ID查询帮助信息
        /// <summary>
        /// 根据ID查询帮助信息
        /// </summary>
        /// <param name="leaveID">帮助信息编号</param>
        /// <returns>查询成功返回true,否则返回false</returns>
        public bool GetHelpContentByID(int helpID)
        {
            DataTable dt = DBAction.GetDTFromSQL("Select * From " + ETableName.HelpContent + " where id=" + helpID);
            if (dt.Rows.Count < 1)
            {
                return false;
            }
            this._ID = helpID;
            this._Tile = Convert.ToString(dt.Rows[0]["Tile"]);
            this._Content = Convert.ToString(dt.Rows[0]["Content"]);
            this._SubjectID = Convert.ToInt32(dt.Rows[0]["SubjectID"]);
            return true;
        }
        #endregion

        #region 添加帮助信息
        /// <summary>
        /// 添加帮助信息
        /// </summary>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddHelpContent()
        {
            RParams RP = new RParams();
            RP.Add("Tile", this._Tile, SqlDbType.VarChar);
            RP.Add("Content", this._Content, SqlDbType.VarChar);
            RP.Add("SubjectID", this._SubjectID, SqlDbType.Int);
            return AddHelpContent(RP);
        }
        /// <summary>
        /// 添加帮助信息
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddHelpContent(RParams RP)
        {
            return DBAction.Insert(ETableName.HelpContent, RP);
        }
        #endregion

        #region 根据ID删除帮助信息
        /// <summary>
        /// 根据ID删除帮助信息
        /// </summary>
        /// <param name="helpID">帮助信息编号</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelHelpContent(int helpID)
        {
            RParams RP = new RParams();
            RP.Add("ID", helpID, SqlDbType.Int);
            string whereFields = "ID=@ID";
            return DBAction.Delete(ETableName.HelpContent, whereFields, RP);
        }
        /// <summary>
        /// 根据ID删除帮助信息
        /// </summary>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelHelpContent()
        {
            return DelHelpContent(this._ID);
        }
        #endregion

        #region 根据分类ID删除帮助信息
        /// <summary>
        /// 根据分类ID删除帮助信息
        /// </summary>
        /// <param name="helpID">分类ID</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelHelpContentBySubjectID(int sbujectID)
        {
            RParams RP = new RParams();
            RP.Add("SubjectID", sbujectID, SqlDbType.Int);
            string whereFields = "SubjectID=@SubjectID";
            return DBAction.Delete(ETableName.HelpContent, whereFields, RP);
        }
        /// <summary>
        /// 根据分类ID删除帮助信息
        /// </summary>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelHelpContentBySubjectID()
        {
            return DelHelpContentBySubjectID(this._SubjectID);
        }
        #endregion

        #region 修改帮助信息
        /// <summary>
        /// 修改帮助信息
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool MdfHelpContent()
        {
            RParams RP = new RParams();
            RP.Add("ID", this.ID, SqlDbType.Int);
            RP.Add("Tile", this._Tile, SqlDbType.VarChar);
            RP.Add("Content", this._Content, SqlDbType.Int);
            RP.Add("SubjectID", this._SubjectID, SqlDbType.Int);
            string colFields = "Tile,Content,SubjectID";
            string whereFields = "ID=@ID";
            return MdfHelpContent(colFields, whereFields, RP);
        }
        /// <summary>
        ///  修改帮助信息
        /// </summary>
        /// <param name="colFields">修改的列</param>
        /// <param name="whereFields">修改条件</param>
        /// <param name="RP">数据集</param>
        ///  <returns>修改成功返回true,否则返回false</returns>
        public bool MdfHelpContent(string colFields, string whereFields, RParams RP)
        {
            return DBAction.Update(ETableName.HelpContent, colFields, whereFields, RP);
        }
        #endregion
        #endregion
    }
}
